<?php
/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: space_notice.php 34047 2013-09-25 04:41:45Z nemohou $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
$extcredits2 = $_POST['extcredits2'];
if($extcredits2 <= 0){
	showmessage('充值金额不能为0或小于0', 'home.php?mod=space&do=topup', array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true));
	exit;
}
if(!preg_match('/^[0-9]+(.[0-9]{1,2})?$/',$extcredits2)){
	showmessage('充值金额不能超过2位小数', 'home.php?mod=space&do=topup', array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true));
	exit;
}
if(!empty($_POST['extcredits2'])){
	$uid=$space[uid];
    $res = DB::fetch_first("SELECT extcredits2 FROM pre_common_member_count where uid = $uid");
    $data = [
	    'extcredits2' => $res['extcredits2'] + $_POST['extcredits2'],
    ];
    $order = [
        'orderid' => time().rand(100,999), //订单编号
        'uid' => $uid, //用户ID
        'username' => $space['username'], //用户名
        'money' => $_POST['extcredits2'], //金额
        'starttime' => date('YmdHis'), //下单开始时间
        'paystate' => 0
    ];
    $orders = DB::insert('common_member_topup',$order,true);
   /* $money = DB::update('common_member_count',$data,array('uid'=>$uid));*/
    if($orders){
        showmessage('充值成功,请前往付款', "pay/example/native.php?id={$orders}&uid=$uid&money={$order['money']}&orderid={$order['orderid']}&username={$order['username']}&starttime={$order['starttime']}&extcredits2={$data['extcredits2']}", array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true));
/*		showmessage('充值成功,请前往付款', "home.php?mod=space&do=pay&orderid={$order['orderid']}", array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true));*/
    }else{
        showmessage('充值失败', 'home.php?mod=space&do=topup&orderid', array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true));
    }
}
?>